// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class MF_CLIN_STUDY_MFN_M07 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("4 MFE",4)]
  	    [HL7Field(HL7Version.v23, 4, HL7Repeat.False, HL7Required.True,"MFE")]
	    public MFE MFE {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("5 CM0",5)]
  	    [HL7Field(HL7Version.v23, 5, HL7Repeat.False, HL7Required.True,"CM0")]
	    public CM0 CM0 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("6 MF_PHASE_SCHED_DETAIL",6)]
  	    [HL7Field(HL7Version.v23, 6, HL7Repeat.False, HL7Required.False,"MF_PHASE_SCHED_DETAIL_MFN_M07")]
	    public MF_PHASE_SCHED_DETAIL_MFN_M07 MF_PHASE_SCHED_DETAIL {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			MFE = PopSegmentParseAndCheckRequired<MFE>(availableData, options, "MFE");
			CM0 = PopSegmentParseAndCheckRequired<CM0>(availableData, options, "CM0");
			MF_PHASE_SCHED_DETAIL = ProcessGroup<MF_PHASE_SCHED_DETAIL_MFN_M07>(availableData, options, "MF_PHASE_SCHED_DETAIL");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isMFE = availableData.StartsWith("MFE", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("MFE", options.Version) || isMFE) {
				return isMFE;
			}
			bool isCM0 = availableData.StartsWith("CM0", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("CM0", options.Version) || isCM0) {
				return isCM0;
			}
			MF_PHASE_SCHED_DETAIL_MFN_M07 testMF_PHASE_SCHED_DETAIL_MFN_M07 = new MF_PHASE_SCHED_DETAIL_MFN_M07();
			bool grpCCMF_PHASE_SCHED_DETAIL_MFN_M07 = (testMF_PHASE_SCHED_DETAIL_MFN_M07.CanConsume(availableData, options));
			if (IsRequired("MF_PHASE_SCHED_DETAIL", options.Version) || grpCCMF_PHASE_SCHED_DETAIL_MFN_M07) {
				return grpCCMF_PHASE_SCHED_DETAIL_MFN_M07;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "MF_CLIN_STUDY";
			}
        }

        static MF_CLIN_STUDY_MFN_M07() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(MF_CLIN_STUDY_MFN_M07));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (MFE != null) {
			string segmentValue = MFE.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (CM0 != null) {
			string segmentValue = CM0.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (MF_PHASE_SCHED_DETAIL != null) {
			string segmentValue = MF_PHASE_SCHED_DETAIL.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

